﻿using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;

namespace BullsAndCowsTests
{
    [TestClass()]
    public class BullsAndCowsTest
    {
        
        [TestMethod()]
        public void BullsAndCowsConstructorTest()
        {
            BullsAndCows target = new BullsAndCows();
            uint zero = 0;
            Assert.AreEqual(zero, target.Attemps);
            Assert.AreEqual(zero, target.BullsCount);
            Assert.AreEqual(zero, target.CowsCount);
        }

        [TestMethod()]
        [DeploymentItem("CowsBulls.exe")]
        public void CalculateSecretNumberTest()
        {
            BullsAndCows target = new BullsAndCows();
            int number = 7158;
            target.CalculateSecretNumber(number);
            Assert.IsTrue(target.SecretNumberArray[0] == 7);
            Assert.IsTrue(target.SecretNumberArray[1] == 1);
            Assert.IsTrue(target.SecretNumberArray[2] == 5);
            Assert.IsTrue(target.SecretNumberArray[3] == 8);
        }

        [TestMethod()]
        public void CowsCountTest()
        {
            BullsAndCows target = new BullsAndCows(); 
            uint expected = 100; 
            uint actual;
            target.CowsCount = expected;
            actual = target.CowsCount;
            Assert.AreEqual(expected, actual);
        }

        [TestMethod()]
        public void SecretNumberArrayTest()
        {
            BullsAndCows target = new BullsAndCows(); 
            uint[] expected = new uint[] {1,2,3,4}; 
            uint[] actual;
            target.SecretNumberArray = expected;
            actual = target.SecretNumberArray;
            Assert.AreEqual(expected, actual);
        }

        [TestMethod()]
        public void BullsCountTest()
        {
            BullsAndCows target = new BullsAndCows(); 
            uint expected = 123; 
            uint actual;
            target.BullsCount = expected;
            actual = target.BullsCount;
            Assert.AreEqual(expected, actual);
        }

        [TestMethod()]
        public void AttempsTest()
        {
            BullsAndCows target = new BullsAndCows(); 
            uint expected = 4;
            uint actual;
            target.Attemps = expected;
            actual = target.Attemps;
            Assert.AreEqual(expected, actual);
        }

        [TestMethod()]
        public void ResetGameTest()
        {
            BullsAndCows target = new BullsAndCows();
            target.ResetGame();
            Assert.IsTrue(target.Attemps == 0);
            Assert.IsTrue(target.BullsCount == 0);
            Assert.IsTrue(target.CowsCount == 0);
        }

        [TestMethod()]
        public void RepresentGuestNumberInArrayTest()
        {
            BullsAndCows target = new BullsAndCows();
            int guessNumber = 3623; 
            uint[] expected = new uint[] {3,6,2,3}; 
            uint[] actual;
            actual = target.RepresentGuestNumberInArray(guessNumber);
            Assert.IsTrue(expected[0] == actual[0]);
            Assert.IsTrue(expected[1] == actual[1]);
            Assert.IsTrue(expected[2] == actual[2]);
            Assert.IsTrue(expected[3] == actual[3]);
        }

        [TestMethod()]
        public void IsGuestNumberRightTest()
        {
            BullsAndCows target = new BullsAndCows(); 
            target.CalculateSecretNumber(1234);
            target.SecretNumber = 1234;
            int guestNumber = 1234; 
            bool actual = target.IsGuestNumberRight(guestNumber);
            Assert.IsTrue(actual);
        }

        [TestMethod()]
        public void GetCowsTest()
        {
            BullsAndCows target = new BullsAndCows(); 
            target.CalculateSecretNumber(4123);
            uint[] guestNumberArray = new uint[] {1,2,3,4}; 
            target.GetCows(guestNumberArray);
            Assert.IsTrue(target.CowsCount == 4);
        }

        [TestMethod()]
        public void GetBullsTest()
        {
            BullsAndCows target = new BullsAndCows();
            target.CalculateSecretNumber(1234);
            uint[] guestNumberArray = new uint[] { 1, 2, 3, 4 };
            target.GetBulls(guestNumberArray);
            Assert.IsTrue(target.BullsCount == 4);
        }

        [TestMethod()]
        public void GenerateSecretNumberTest()
        {
            BullsAndCows target = new BullsAndCows(); 
            target.GenerateSecretNumber();
            target.CalculateSecretNumber(target.SecretNumber);
            Assert.IsTrue(target.SecretNumberArray[0] >= 0 && target.SecretNumberArray[0] <= 9);
            Assert.IsTrue(target.SecretNumberArray[1] >= 0 && target.SecretNumberArray[1] <= 9);
            Assert.IsTrue(target.SecretNumberArray[2] >= 0 && target.SecretNumberArray[2] <= 9);
            Assert.IsTrue(target.SecretNumberArray[3] >= 0 && target.SecretNumberArray[3] <= 9);
        }

        [TestMethod()]
        [Ignore]
        public void PlayGameTest()
        {
            BullsAndCows target = new BullsAndCows(); 
            target.PlayGame();
        }

        [TestMethod()]
        public void GetSecretDigitTest()
        {
            BullsAndCows target = new BullsAndCows(); 
            target.CalculateSecretNumber(1234);
            string result = target.GetSecretDigit();
            int count = 0;
            for (int i = 0; i < result.Length; i++)
            {
                if (result[i] == 'X')
                    count++;
            }
            Assert.IsTrue(count == 3);
        }
    }
}
